<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN"    "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">
<%@ page language="java" contentType="application/xhtml+xml; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="org.j4me.deviceinfo.data.*"%>
<%@page import="java.util.*"%>
<%@page import="java.net.URLEncoder"%>

<%! 
String encode(String text)
{
	

		if(text == null)
			return null;
		StringBuffer buffer = new StringBuffer();
	        char[] block = null;
	        int i;
	        int last = 0;
	        int size = text.length();

	        for (i = 0; i < size; i++) {
	            String entity = null;
	            char c = text.charAt(i);

	            switch (c) {
	                case '<':
	                    entity = "&lt;";

	                    break;

	                case '>':
	                    entity = "&gt;";

	                    break;

	                case '\'':

	                   
	                        entity = "&apos;";
	                   

	                    break;

	                case '\"':
	                        entity = "&quot;";

	                    break;

	                case '&':
	                    entity = "&amp;";

	                    break;

	                case '\t':
	                case '\n':
	                case '\r':

	                    // don't encode standard whitespace characters
	                    break;

	                default:

	                    if (c < 32)  {
	                        entity = "&#" + (int) c + ";";
	                    }

	                    break;
	            }

	            if (entity != null) {
	                if (block == null) {
	                    block = text.toCharArray();
	                }

	                buffer.append(block, last, i - last);
	                buffer.append(entity);
	                last = i + 1;
	            }
	        }

	        if (last == 0) {
	            return text;
	        }

	        if (last < size) {
	            if (block == null) {
	                block = text.toCharArray();
	            }

	            buffer.append(block, last, i - last);
	        }

	        String answer = buffer.toString();
	        buffer.setLength(0);

	        return answer;
	   
}
%>

<%


DeviceDb db = DeviceDb.getInstance();
Brand brand = db.getBrand(request.getParameter("b"));
Model model = brand.getModel(request.getParameter("m"));

%>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml;; charset=UTF-8" />
<title>J4ME Device Database - <%= brand.getName() %> - <%=model.getName() %> </title>
</head>
<body>

<h2>Device  - <%= brand.getName() %> - <%=model.getName() %>  </h2>

<table>
<tr><td>Device count</td><td><%=model.getDeviceCount() %></td></tr>
<tr><td>Hit count</td><td><%=model.getHitCount() %></td></tr>
</table>



<%
Enumeration<Device> devices = model.getDevices();
while(devices.hasMoreElements())
{
	Device d = devices.nextElement();
	%>

	<h3><%=encode(d.getBrand()) + "-" + encode(d.getModel())%></h3>
	<p>Created <%=d.getCreated().toLocaleString()%>, Operator <%=encode(d.getOperator())%></p>
	
	
	<h4> Properties</h4>
	<table border="1" ><tr><td>Key</td><td>Value</td></tr>
	<%
	Enumeration<Kvp> properties =d.getProperties() ;
	while(properties.hasMoreElements())
	{
		Kvp prop = properties.nextElement();
	%>
		<tr><td> <%=encode(prop.getKey()) %></td><td> <%=encode(prop.getValue()) %></td></tr>
	<%		
	}
	%>
	</table>
	<p/>
	<table>
	<tr><td><b>JSR</b></td><td> </td><td><b>Media content</b></td></tr>
	<tr><td>
	<table border="1" ><tr><td>JSR</td><td>Supported</td></tr>
	
	<%
	Enumeration<Jsr> Jsrs =d.getJsr() ;
	while(Jsrs.hasMoreElements())
	{
		Jsr jsr = Jsrs.nextElement();
	%>
		<tr><td> <%=jsr.getJsr() %></td><td valign="center"> <%=jsr.isHas()?"X":"" %></td></tr>
	<%		
	}
	%>
	</table>
	</td>
		
	<td/>
	<td valign="top">
	<table border="1" ><tr><td>Content Type</td><td>protocols</td></tr>
	<%
	Enumeration<MediaContent> contents =d.getContents() ;
	while(contents.hasMoreElements())
	{
		MediaContent content = contents.nextElement();
	%>
		<tr><td> <%=encode(content.getMimeType()) %> </td><td><%=encode(content.getProtocols().toString()) %></td></tr>
	<%		
	}
	%>
	</table>
	</td>
	</tr>
	</table>
	
	<h4> Keyboard mapping</h4>
	<p>(#Uxxxx = unicode character where xxxx is the hexadecimal value)</p> 
	<table border="1">
	<tr><td>Key Code</td><td>Game code</td><td>Name</td></tr>
	<%
	Enumeration<Key> keys =d.getKeys() ;
	while(keys.hasMoreElements())
	{
		Key key = keys.nextElement();
	%>
		<tr><td align="center"><%=key.getKey() %></td><td align="center"><%=key.getGameaction() %></td><td><%=encode(key.getName()) %></td></tr>
	<%		
	}
	%>
	</table>
	
	<p/>
<%}%>

</body>
</html>